﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using HMS.Common;
using System.Data.EntityClient;
using System.Data.Objects;

namespace POC
{
    public partial class JSON : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindCombo1();
        }

        private void BindCombo()
        {
            TreeEntities treeContext = new TreeEntities();
            IQueryable<X_HIERARCHIES> treeQuery = from t in treeContext.X_HIERARCHIES
                                                  where t.HIERARCHY_ID > 1
                                                  select t;

            List<DropdownListItem> listHierarchies = new List<DropdownListItem>();
            listHierarchies.Add(new DropdownListItem("--Select--", ""));
            foreach (X_HIERARCHIES TQ in treeQuery)
            {
                listHierarchies.Add(new DropdownListItem(TQ.HIER_NAME.ToString(), TQ.HIERARCHY_ID.ToString(), ""));
            }
            JavaScriptSerializer js = new JavaScriptSerializer();
            Response.Write(js.Serialize(listHierarchies));
        }

        private void BindCombo1()
        {
            TreeEntities treeContext = new TreeEntities();
            /*IQueryable<X_HIERARCHIES> treeQuery = from t in treeContext.C_ATTR_NODES
                                                  .Where("HIERARCHY_ID == @0", objParams)
                                                  .Select("new(NODE_NAME as NODENAME)");*/

            //var items = db.InventoryItem.Where("Category.ID = @0", 7).ToList<InventoryItem>();
            ObjectQuery<C_ATTR_NODES> treeQuery = treeContext.C_ATTR_NODES.Where("HIERARCHY_ID <> 1");
            List<C_ATTR_NODES> treeNodes = treeQuery.ToList();

            List<DropdownListItem> listHierarchies = new List<DropdownListItem>();
            listHierarchies.Add(new DropdownListItem("--Select--", ""));
            foreach (C_ATTR_NODES TQ in treeNodes)
            {
                listHierarchies.Add(new DropdownListItem(TQ.NODE_NAME, TQ.NODE_ID.ToString(), ""));
            }
            JavaScriptSerializer js = new JavaScriptSerializer();
            Response.Write(js.Serialize(listHierarchies));
            
        }
    }
}